package com.ys.nms.module.business.service.devicesLog;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.ys.nms.module.business.controller.admin.devicesLog.vo.*;
import com.ys.nms.module.business.dal.dataobject.devicesLog.DevicesLogDO;
import com.ys.nms.framework.common.pojo.PageResult;
import com.ys.nms.framework.common.pojo.PageParam;
import com.ys.nms.framework.common.util.object.BeanUtils;

import com.ys.nms.module.business.dal.mysql.devicesLog.DevicesLogMapper;

import static com.ys.nms.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.ys.nms.framework.common.util.collection.CollectionUtils.convertList;
import static com.ys.nms.framework.common.util.collection.CollectionUtils.diffList;
import static com.ys.nms.module.business.enums.ErrorCodeConstants.*;

/**
 * 设备日志 Service 实现类
 *
 * @author zzy
 */
@Service
@Validated
public class DevicesLogServiceImpl implements DevicesLogService {

    @Resource
    private DevicesLogMapper devicesLogMapper;

    @Override
    public Integer createDevicesLog(DevicesLogSaveReqVO createReqVO) {
        // 插入
        DevicesLogDO devicesLog = BeanUtils.toBean(createReqVO, DevicesLogDO.class);
        devicesLogMapper.insert(devicesLog);

        // 返回
        return devicesLog.getLogId();
    }

    @Override
    public void updateDevicesLog(DevicesLogSaveReqVO updateReqVO) {
        // 校验存在
        validateDevicesLogExists(updateReqVO.getLogId());
        // 更新
        DevicesLogDO updateObj = BeanUtils.toBean(updateReqVO, DevicesLogDO.class);
        devicesLogMapper.updateById(updateObj);
    }

    @Override
    public void deleteDevicesLog(Integer id) {
        // 校验存在
        validateDevicesLogExists(id);
        // 删除
        devicesLogMapper.deleteById(id);
    }

    @Override
        public void deleteDevicesLogListByIds(List<Integer> ids) {
        // 删除
        devicesLogMapper.deleteByIds(ids);
        }


    private void validateDevicesLogExists(Integer id) {
        if (devicesLogMapper.selectById(id) == null) {
            throw exception(DEVICES_LOG_NOT_EXISTS);
        }
    }

    @Override
    public DevicesLogDO getDevicesLog(Integer id) {
        return devicesLogMapper.selectById(id);
    }

    @Override
    public PageResult<DevicesLogDO> getDevicesLogPage(DevicesLogPageReqVO pageReqVO) {
        return devicesLogMapper.selectPage(pageReqVO);
    }

}